<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Veh_Insurance_Edit extends Page
{
       public $Label12 = null;
       public $hfError = null;
       public $lblrem = null;
       public $lblto = null;
       public $lblper = null;
       public $lblpol = null;
       public $cmbIntermed = null;
       public $cmbInsuranceComp = null;
       public $Label1 = null;
       public $memoRemarks = null;
       public $Label5 = null;
       public $edDue = null;
       public $Label4 = null;
       public $jtdaterenew = null;
       public $Label78 = null;
       public $jtdatecover = null;
       public $Label77 = null;
       public $lblAdress = null;
       public $Label42 = null;
       public $edPolicyNum = null;
       public $lblPolicy = null;
       public $JSValidate = null;
       public $imgBack = null;
       public $hiddenIns = null;
       public $hiddenId = null;
       public $Image2 = null;
       public $btnSubmit = null;
       public $btnCancel = null;
       public $Label76 = null;
       public $edtotAmt = null;
       public $edtotPrice = null;
       public $edPremium2 = null;
       public $edOthersSum2 = null;
       public $edCat2 = null;
       public $edCat1 = null;
       public $edOthersSum1 = null;
       public $edPremium1 = null;
       public $Label79 = null;
       public $Label73 = null;
       public $Label80 = null;
       public $Label72 = null;
       public $Label71 = null;
       public $edamtELPD = null;
       public $edPrELPD = null;
       public $edPrELBI = null;
       public $edamtELBI = null;
       public $Label65 = null;
       public $Label41 = null;
       public $edPrOD = null;
       public $edamtOD = null;
       public $edPrCTPL = null;
       public $edamtCTPL = null;
       public $Label75 = null;
       public $Label74 = null;
       public $Label40 = null;
       public $Label39 = null;
       public $edAgentInsurance = null;
       public $edCompInsurance = null;
       function edDueJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edDue','lblrem');
       <?php

       }

       function edPolicyNumJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edPolicyNum','lblpol');
       <?php

       }

       function edDueJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       var numero = document.getElementById("edDue").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edDue").value = numero;
       <?php

       }

       function btnCancelClick($sender, $params)
       {
       redirect('veh_insurance_list.php?veh='.$this->hiddenId->getValue());


       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }


       function btnSubmitClick($sender, $params)
       {

       $this->validateRequired($this->jtdaterenew->Text, 'lblto');
       $this->validateRequired($this->jtdatecover->Text, 'lblper');
       $this->validateRequired($this->edPolicyNum->Text, 'lblpol');
       $this->validateRequired($this->edDue->Text, 'lblrem');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {
       $tot_coverage = $this->edtotAmt->Text;
       $tot_price = $this->edtotPrice->Text;
       $tot_c = $this->commafy($tot_coverage);
       $tot_p = $this->commafy($tot_price);

       mysql_query("update veh_insurance_dynamic_tbl set
       policy_num = '" . $this->edPolicyNum->Text . "',
       company = '" . $this->cmbInsuranceComp->getItemIndex() . "',
       agent = '" . $this->cmbIntermed->getItemIndex() . "',
       category1 = '".$this->edCat1->Text."',
       category2 = '".$this->edCat2->Text."',
       ctpl_amt = '".$this->edamtCTPL->Text."',
       od_amt = '".$this->edamtOD->Text."',
       elbi_amt = '".$this->edamtELBI->Text."',
       elpd_amt = '".$this->edamtELPD->Text."',
       other1_amt = '".$this->edOthersSum1->Text."',
       other2_amt = '".$this->edOthersSum2->Text."',
       tot_amt = '".$tot_coverage."',
       ctpl_price = '".$this->edPrCTPL->Text."',
       od_price = '".$this->edPrOD->Text."',
       elbi_price = '".$this->edPrELBI->Text."',
       elpd_price = '".$this->edPrELPD->Text."',
       premium1_amt = '".$this->edPremium1->Text."',
       premium2_amt = '".$this->edPremium2->Text."',
       tot_price = '".$tot_price."',
       cover_date = '".$this->jtdatecover->Text."',
       renewal_date = '".$this->jtdaterenew->Text."',
       due_days = '".$this->edDue->Text."',
       remarks = '".$this->memoRemarks->Text."'
       where insurance_id='" . $this->hiddenIns->getValue() . "'")or die("UPDATE INSURANCE - " . mysql_error());


       $query_update = "update veh_reminder_tbl set
       due_date = '".$this->jtdaterenew->Text."',
       rem_time = '".$this->edDue->Text."',
       description = '".$this->memoRemarks->Text."',
       vendor = '".$this->cmbInsuranceComp->getItemIndex()."'
       where vehicle_id ='".$this->hiddenId->getValue()."' and insurance_id = '".$this->hiddenIns->getValue()."'";
       mysql_query($query_update)or die ("UPDATE INSURANCE REMINDER-".mysql_error());

       //die($query_update);

       redirect('veh_insurance_list.php?veh='.$this->hiddenId->getValue());
       }

       }


       function commafy($_)
       {
        return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $_ ) ) );
       }


       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }




       function Veh_Insurance_EditCreate($sender, $params)
       {
        $id = $_GET['veh'];
        if($id!=''||$id!=null)
        $this->hiddenId->setValue($id);

        $this->hfError->setValue('0');

        $ins = $_GET['ins'];
        if($ins!=''||$ins!=null)
        $this->hiddenIns->setValue($ins);

        $this->imgBack->setLink('veh_insurance_list.php?veh='.$this->hiddenId->getValue());


        $query_insurance = "select * from veh_insurance_dynamic_tbl where vehicle_id= '" .$this->hiddenId->getValue(). "' and insurance_id='".$this->hiddenIns->getValue()."'";
        $result_insurance_show = mysql_query($query_insurance)or die("SELECT INSURANCE - " . mysql_error());
        $row_insurance = mysql_fetch_array($result_insurance_show);

        $this->lblpol->Caption = '';
        $this->lblto->Caption = '';
        $this->lblper->Caption = '';
        $this->lblrem->Caption = '';


        $ctpl = $row_insurance['ctpl_amt'];
        $od = $row_insurance['od_amt'];
        $elbi = $row_insurance['elbi_amt'];
        $elpd = $row_insurance['elpd_amt'];
        $cat1 = $row_insurance['category1'];
        $cat2 = $row_insurance['category2'];
        $other1 = $row_insurance['other1_amt'];
        $other2 = $row_insurance['other2_amt'];
        $premium1 = $row_insurance['premium1_amt'];
        $premium2 = $row_insurance['premium2_amt'];

        $this->edPolicyNum->Text = $row_insurance['policy_num'];
        $this->cmbInsuranceComp->ItemIndex = $row_insurance['company'];
        $this->cmbIntermed->ItemIndex = $row_insurance['agent'];
        $this->edamtCTPL->Text = $ctpl;
        $this->edamtOD->Text = $od;
        $this->edamtELBI->Text = $elbi;
        $this->edamtELPD->Text = $elpd;
        $this->edCat1->Text = $cat1;
        $this->edCat2->Text = $cat2;
        $this->edOthersSum1->Text = $other1;
        $this->edOthersSum2->Text = $other2;
        $this->edPremium1->Text = $premium1;
        $this->edPremium2->Text = $premium2;
        $this->edtotAmt->Text = $row_insurance['tot_amt'];
        $this->edPrCTPL->Text = $row_insurance['ctpl_price'];
        $this->edPrOD->Text = $row_insurance['od_price'];
        $this->edPrELBI->Text = $row_insurance['elbi_price'];
        $this->edPrELPD->Text = $row_insurance['elpd_price'];
        $this->edtotPrice->Text = $row_insurance['tot_price'];
        $this->jtdatecover->Text = $row_insurance['cover_date'];
        $this->jtdaterenew->Text = $row_insurance['renewal_date'];
        $this->edDue->Text = $row_insurance['due_days'];
        $this->memoRemarks->Lines = array();
        $this->memoRemarks->Text = $row_insurance['remarks'];

       $result_vendor = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_vendor = mysql_fetch_array($result_vendor))
       {
            $this->cmbInsuranceComp->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
            $this->cmbIntermed->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
       }


       }

       function edOthersSum2JSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edOthersSum2").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edOthersSum2").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edOthersSum1JSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edOthersSum1").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edOthersSum1").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edamtELPDJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edamtELPD").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edamtELPD").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edamtELBIJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edamtELBI").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edamtELBI").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edamtODJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edamtOD").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edamtOD").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edamtCTPLJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edamtCTPL").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edamtCTPL").value = numero;

       document.Veh_Insurance_Edit.edtotAmt.value = Number(document.Veh_Insurance_Edit.edamtCTPL.value) +
   Number(document.Veh_Insurance_Edit.edamtOD.value) +
   Number(document.Veh_Insurance_Edit.edamtELBI.value) +
   Number(document.Veh_Insurance_Edit.edamtELPD.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum1.value) +
   Number(document.Veh_Insurance_Edit.edOthersSum2.value);

       <?php

       }

       function edPremium2JSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPremium2").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPremium2").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

       function edPremium1JSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPremium1").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPremium1").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

       function edPrELPDJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPrELPD").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPrELPD").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

       function edPrELBIJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPrELBI").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPrELBI").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

       function edPrODJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPrOD").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPrOD").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

       function edPrCTPLJSKeyUp($sender, $params)
       {

       ?>
       var numero = document.getElementById("edPrCTPL").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edPrCTPL").value = numero;

       document.Veh_Insurance_Edit.edtotPrice.value = Number(document.Veh_Insurance_Edit.edPrCTPL.value) +
   Number(document.Veh_Insurance_Edit.edPrOD.value) +
   Number(document.Veh_Insurance_Edit.edPrELBI.value) +
   Number(document.Veh_Insurance_Edit.edPrELPD.value) +
   Number(document.Veh_Insurance_Edit.edPremium1.value) +
   Number(document.Veh_Insurance_Edit.edPremium2.value);

       <?php

       }

}

global $application;

global $Veh_Insurance_Edit;

//Creates the form
$Veh_Insurance_Edit=new Veh_Insurance_Edit($application);

//Read from resource file
$Veh_Insurance_Edit->loadResource(__FILE__);

//Shows the form
$Veh_Insurance_Edit->show();

?>